package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "管理端-订单接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 订单分页搜索
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("订单搜索开始====>");
        PageResult pageResult = orderService.pageFindOrder(ordersPageQueryDTO);
        log.info("<====订单搜索结束");
        return Result.success(pageResult);
    }

    /**
     * 订单详情
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    @ApiOperation("订单详情")
    public Result<OrderVO> details(@PathVariable Long id){
        log.info("订单详情查询开始====>");
        OrderVO orderVO = orderService.findOrderDetail(id);
        log.info("<====订单详情查询结束");
        return Result.success(orderVO);
    }

    /**
     * 订单取消
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("取消订单开始====>");
        orderService.cancel(ordersCancelDTO);
        log.info("<====取消订单结束");
        return Result.success();
    }

    /**
     * 订单拒绝
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("/rejection")
    @ApiOperation("订单拒绝")
    public Result rejection(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("订单拒绝开始====>");
        orderService.rejection(ordersCancelDTO);
        log.info("<====订单拒绝结束");
        return Result.success();
    }

    /**
     * 订单确认
     * @param ordersConfirmDTO
     * @return
     */
    @PutMapping("/confirm")
    @ApiOperation("确认订单")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("订单确认开始====>");
        orderService.confirm(ordersConfirmDTO);
        log.info("<====订单确认结束");
        return Result.success();
    }

    /**
     * 订单派送
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("订单派送")
    public Result delivery(@PathVariable Long id){
        log.info("订单派送开始====>");
        orderService.delivery(id);
        log.info("<====订单派送结束");
        return Result.success();
    }

    /**
     * 订单完成
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("订单完成")
    public Result complete(@PathVariable Long id){
        log.info("订单完成开始====>");
        orderService.complete(id);
        log.info("<====订单完成结束");
        return Result.success();
    }

    /**
     * 统计派送接口
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation("统计派送")
    public Result<OrderStatisticsVO> statistics(){
        log.info("统计开始====>");
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        log.info("<====统计结束");
        return Result.success(orderStatisticsVO);
    }

}
